package com.hy.controller;

import com.hy.grace.result.GraceJSONResult;
import com.hy.pojo.Job;
import com.hy.pojo.bo.JobBO;
import com.hy.service.JobService;
import com.hy.utils.PagedGridResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/job")
public class JobController {

    @Autowired
    private JobService jobService;

    /**
     * 创建或者更新职位
     * @param jobBO
     * @return
     */
    @PostMapping("/createOrUpdate")
    public GraceJSONResult createOrUpdate(@RequestBody JobBO jobBO) {
        jobService.createOrUpdate(jobBO);
        return GraceJSONResult.ok();
    }

    /**
     * 查询职位列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public GraceJSONResult queryJobList(@RequestParam(defaultValue = "1",name = "page") Integer page,
                                       @RequestParam(defaultValue = "10",name = "pageSize") Integer pageSize) {
        PagedGridResult pagedGridResult = jobService.queryJobList(page, pageSize);
        return GraceJSONResult.ok(pagedGridResult);
    }

    /**
     * 查询职位详情
     * @param jobId
     * @return
     */
    @GetMapping("/detail")
    public GraceJSONResult details(String jobId) {
        Job details = jobService.getDetails(jobId);
        return GraceJSONResult.ok(details);
    }

    /**
     * 删除职位
     * @return
     */
    @DeleteMapping("/delete")
    public GraceJSONResult delete(String jobId) {
        jobService.delete(jobId);
        return GraceJSONResult.ok();
    }

    /**
     * 查询并且获得所有包含名称的岗位列表
     * @param
     * @return
     */
    @GetMapping("/nameList")
    public GraceJSONResult nameList() {
        List<HashMap<String, String>> nameList = jobService.nameList();
        return GraceJSONResult.ok(nameList);
    }
}
